package algotithm.interview.gensheixueGo.test1;

import java.io.*;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author zhouyanxiang
 * @Date 2021-04-2021/4/15-15:45
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(reader.readLine());
        int t = n;
        int index = 0;
        int[][] arr = new int[n][2];
        while (t-- > 0) {
            String[] str = reader.readLine().split(" ");
            arr[index][0] = Integer.parseInt(str[0]);
            arr[index][1] = Integer.parseInt(str[1]);
            index++;
        }
        Arrays.sort(arr, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[1] - o2[1];
            }
        });

        int r = arr[0][1];
        int ans = 1;
        for (int i = 1; i < n; i++) {
            if (arr[i][0] >= r) {
                ans++;
                r = arr[i][1];
            }
        }
        writer.write(ans + "\n");
        writer.flush();
        writer.close();
        reader.close();
     }

}
